﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Biblioteca.Interfaces;
using System.Data;

namespace Biblioteca.Models
{
    public class EditorialModel : IEditorial
    {
        private BibliotecaStore db;

        public EditorialModel(BibliotecaStore data)
        {
            this.db = data;
        }


        public void crearEditorial(Editorial e)
        {
            db.Editorials.AddObject(e);
            db.SaveChanges();
        }

        public void modificarEditorial(Editorial e)
        {
            db.Editorials.Attach(e);
            db.ObjectStateManager.ChangeObjectState(e, EntityState.Modified);
            db.SaveChanges();
        }

        public void eliminarEditorial(Editorial e)
        {

            db.Editorials.DeleteObject(e);
            db.SaveChanges();
        }

        public Editorial getSingle(int idEditorial)
        {
            return db.Editorials.Single(e => e.IdEditorial == idEditorial);
        }

        public IList<Editorial> getAll()
        {
            return db.Editorials.OrderBy(m => m.Nombre).ToList();
        }
    }
}